
var init_select = function(){
	
	$('#clientSex').mSelect({
		myClass:'easyui-validatebox',
		width:308,
		baseCode:'Client_Sex_Code',
		dataOptions:'required:true'
	//	source:'server',
		//requestData:{dataBaseCode:'Loan_Source_Code'}
	});
	
	$('#clientMaritalStatus').mSelect({
		myClass:'easyui-validatebox',
		width:308,
		baseCode:'Client_Marital_Status_Code'
	});
	
	$('#clientEducation').mSelect({
		myClass:'easyui-validatebox',
		width:308,
		baseCode:'Client_Education_Code'
	});
	
	$('#clientInsureArea').mSelect({
		myClass:'easyui-validatebox',
		width:308,
		baseCode:'Client_Insure_Area_Code'
	});
	
	
	
};

var initForm = function(){
	$('#_form_default').form({
		url :'sys/Client/addOrUpdate',
		onBeforeLoad : function(param){
			$.messager.progress();
		},
		onLoadSuccess : function(data) {
			//加载完成之后才构建
			if(_is_not_empty(_param_id)){
			//_set_select_selected(data);
			set_disabled();
			}
			$.messager.progress("close");
		},
		onLoadError : function(data) {
			//加载完成之后才构建
			$.messager.progress("close");
			$.messager.alert('提示', "加载内容失败,请重新刷新页面/联系管理员", "error");
		},
		onSubmit : function(param) {
			if (!$(this).form("validate")) {
				$.messager.alert('提示', "提交的选项中,有错误内容,请检查", "error");
				return false;
			}
			$.messager.progress();
		},
		success : function(data) {	
			$.messager.progress("close");
			var jd = eval('(' + data + ')');
			if(!!!jd){
				$.messager.alert('提示', "未知异常", "error");
				return false;
			}
			if(jd.state!=200){
				$.messager.alert('提示', jd.message, "error");
				return false;
			}
			var user = new Object();
			if(_is_empty(_param_id)){
				parent._condition_tab2 = true;
			}
			if(_is_empty(parent._client_user)){
				parent._client_user = new Object();
			}
			parent._client_user['clientIdCard'] = $('#clientCardId').attr('value');
			parent._client_user['clientName'] =$('#clientName').attr('value');
			_deal_result_dailog({'tip_title':'提示信息','tip_content':'操作成功!'},function(){
			parent._set_tab2_success(false);
			});
		    _set_result_open();
			
		}
	});
};

var _to_valid_cardid = function(){
	
};

var _to_valid_username = function(){
	
};


var set_disabled = function(user){//clientIdCard
	if(_is_not_empty(user)){
		if(_is_not_empty(user.clientName)){
			$('#clientName').val(user.clientName);
		}
		if(_is_not_empty(user.clientIdCard)){
			$('#clientIdCard').val(user.clientIdCard);
		}
	}
	$('#clientName').attr('readonly','readonly');
	$('#clientIdCard').attr('readonly','readonly');
	//$('#clientName').attr('disabled','true');
	//$('#clientIdCard').attr('disabled','true');
};


$(function(){
	initForm();
	init_select();
	if(_is_not_empty(_param_id)){
		$("#_form_default").form('load', 'sys/Client/findByPk?pks=' + _param_id);
	}
	$('input[name="confirm_button"]').click(function(){
		$('#_form_default').submit();
	});
	
});
